<template>
  <div>
    <data-view
        :columns="columns"
        :data="data"
        :pagination="pagination"
        :missing-value-fill="'-'">
    </data-view>'
  </div>
</template>

<script>
import moment from 'moment'
import {createdeviceRuntimeLogs, listDeviceRuntimeLogs} from "@/api/deviceRuntimeLog";
import DataView from "../../components/DataView";

export default {
  name: "DeviceRuntimeLog",
  components: { DataView },
  data() {
    return {
      columns: [
        // {
        //   label: "教室ID",
        //   prop: "id",
        //   width: "80",
        //   align: "center"
        // },
        {
          label: "设备名称",
          prop: "deviceName",
          align: "center",
        },
        {
          label: "设备编码",
          prop: "deviceCode",
          align: "center",
        },
        {
          label: "设备类型",
          prop: "deviceType",
          align: "center",
          mapping: {
            "1": {
              value: '灯光',
            },
          },
        },
        {
          label: "日志类型",
          prop: "logType",
          align: "center",
          mapping: {
            "1": {
              value: '设备操作',
            },
          },
        },
        {
          label: "操作类型",
          prop: "operationType",
          align: "center",
          mapping: {
            "1": {
              value: 'HA控制',
            },
          },
        },
        {
          label: "事件",
          prop: "event",
          align: "center",
        },

        {
          label: "时间",
          prop: "time",
          align: "center",
          width:"150",
          formatter: function(row) {
            return moment(row.time).format('YYYY-MM-DD HH:mm')
          }
        },
      ],
      data: [],
      pagination: {
        page: 0,
        pageSize: 10,
        total: 0
      },
      multipleSelection: [],
      tableHeight: window.innerHeight - 170,
    }
  },
  created: function () {
    this.fetchData()
  },
  methods: {
    // 刷新数据
    fetchData() {
      listDeviceRuntimeLogs(1, this.pagination.pageSize).then((response) => {
        this.data = response.data.data.list
        this.pagination = response.data.data.pagination
      })
    },

    // 弹出新建对话框
    handleOpenDialog() {
      console.log("1")
    },

    // 添加新教室
    handleCreate() {
     createdeviceRuntimeLogs().then((response) => {
       this.list = response.data.data.list
       this.pagination = response.data.data.pagination
      })
    },
    formatDate: function (row) {
      return moment(row.time).format('YYYY-MM-DD HH:mm:ss')
    }

  }
}
</script>

<style scoped>

</style>